<?php $uClass     = $sf_params->get('uClass') ?>
<?php $dbClass    = $sf_params->get('dbClass') ?>
<?php $stcClass   = $sf_params->get('stcClass') ?>
<?php $ns         = $sf_params->get('ns') ?>

<?php $object     = isset($object) ? $object : null ?>
<?php $buttons    = array_merge(array('add' => true, 'edit' => false, 'delete' => true), isset($buttons) ? $buttons : array()) ?>
<?php $field_edit = isset($field_edit) ? $field_edit : 'nombre' ?>
<?php $to         = isset($to) ? $to : '@%s_editar' ?>
<?php $bgcolor    = isset($bgcolor) ? $bgcolor : false ?>

<?php $title      = isset($title)  ? $title  : sfInflector::humanize($uClass) ?>
<?php $titles     = isset($titles) ? $titles : $title.'s' ?>

<?php $navigation = isset($navigation) ? $navigation : sprintf('Navegaci&oacute;n Rapida de %s', $title) ?>
<?php $search     = isset($search)     ? $search     : 'Buscar '.$titles ?>

<?php if (has_slot('print_dialog')): ?>
  <?php include_slot('print_dialog') ?>
<?php endif; ?>

  <div>
    <h2>
      <?php echo $title ?>
      <?php if (has_slot('buttons')): ?>
        <?php include_slot('buttons') ?>
      <?php endif; ?>

      <?php if ($buttons['add'] && $sf_user->hasPermission(sprintf('@%s_nuevo', $uClass))): ?>
        <?php if(isset($object)): ?>
          <?php echo link_to('Agregar', sprintf('@%s_nuevo?parent_slug='.$object->getSlug(), $uClass), array('class' => 'action')) ?>
        <?php else: ?>
          <?php echo link_to('Agregar', sprintf('@%s_nuevo', $uClass), array('class' => 'action') ) ?>
        <?php endif ?>
      <?php endif; ?>

      <?php if ($buttons['edit'] && $sf_user->hasPermission(sprintf('@%s_editar', $uClass))): ?>
        <?php echo link_to('Editar', sprintf('@%s_editar?slug=slug', $uClass), array('slug' => $uClass.'_slug=js=v=e', 'class' => 'action')) ?>
      <?php endif; ?>

      <?php if ($buttons['delete'] && $sf_user->hasPermission(sprintf('@%s_elimiar', $uClass))): ?>
        <?php echo link_to('Eliminar', sprintf('@%s_eliminar?slug=slug', $uClass), array('slug' => $uClass.'_slug=js=v=d', 'class' => 'action')) ?>
      <?php endif; ?>
      
    </h2>
    <p><?php echo $titles ?></p>
  </div>

<table class="form"  cellspacing="0" border="0" width="100px">
  <?php if (isset($filter_fields)): ?>
  <tr>
    <td>
      Buscar:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo input_tag_filter('filter', $sf_params->get('filter')) ?>
    </td>
  </tr>
  <?php endif; ?>
                      
  <?php if (has_slot('filter')): ?>
    <?php include_slot('filter') ?>
  <?php endif; ?>
                      
  <?php if (isset($filter_fields)): ?>
    <tr>
      <td>
        Filtrar por:&nbsp;
        <?php echo select_tag
                   (
                     'filter_by', 
                     $filter_fields, 
                     $sf_params->get('filter_by'), 
                     array('onchange' => get_url($uri, $params))
                   )
        ?>
      </td>
    </tr> 
    <tr>
      <td style="padding-right: 1px;">
        <?php echo link_to_get_url('Buscar', $uri, $params) ?>
      </td>
    </tr>
  <?php endif; ?>
</table>       
<table class="content page_block" cellspacing=0 cellpadding=0 width="100%" border="0">
                      <?php if (has_slot('filter')): ?>
                        <?php include_slot('filter') ?>
                      <?php endif; ?>
  <tr>
    <td valign="top" style="padding-top: 3px;">
      <!-- <div class="content_div" style="padding: 3px 7px 0px;"> -->
        <table width="100%" cellspacing="0" cellpadding="5" border="0">
          <tr>
            <td<?php if (has_slot('switch')): ?> colspan="2"<?php endif; ?>>
             
              <table width="100%" cellpadding="2" cellspacing="0" class="list">
                <colgroup>
                  <?php foreach ($fields as $field): ?>
                    <col width="<?php echo $field[0] ?>%">
                  <?php endforeach; ?>
                </colgroup>
                
                <tr style="height: 25px;" class="links">
                  <?php foreach ($fields as $field): ?>
                    <th nowrap align="<?php echo (isset($field[4])) ? $field[4] : 'left' ?>"><?php echo order_link($sf_params->get('order_by'), $field[1], $field[2], $sf_params->get('order'), $uri, $params, isset($field[5]) ? $field[5] : true)  ?></th>
                  <?php endforeach; ?>
                </tr>
                
                <?php $count = 0; foreach ($pager->getResults() as $obj): ?>
                
                  <tr>
                    <?php foreach ($fields as $field): ?>
                      <td nowrap align="<?php echo (isset($field[4])) ? $field[4] : 'left' ?>">
                                                
                        <?php if ($field[3] == 'partial'): ?>
                          <?php include_partial(sprintf('%s/%s', $dbClass, $field[1]), array($uClass => $obj)) ?>
                        <?php elseif (in_array($field[1], array('code','minimum_stock'))): ?>
                          <b><?php echo $obj->$field[3]() ?></b>
                        <?php elseif ($field[3] != 'checkbox'): ?>
                          <?php if ($field[1] == $field_edit && $sf_user->hasPermission(sprintf($to, $uClass))):?>
                            <?php echo link_to($obj->$field[3](), sprintf($to, $uClass).'?slug='.$obj->getSlug()) ?>
                          <?php else: ?>
                            <?php echo $field[3] ? ($obj->$field[3]() != '' ? $obj->$field[3]() : '&nbsp;') : '&nbsp;' ?> <?php //just in case ?>
                          <?php endif ?>
                        <?php else: ?>
                          <input type="checkbox" id="<?php echo $obj->getSlug() ?>" name="<?php echo $obj->getSlug() ?>" 
                                 value="<?php echo $obj->getSlug() ?>" onclick="addRemoveSlug(this, '<?php echo $uClass ?>_slug');" />
                        <?php endif; ?>                        
                      </td>
                    <?php endforeach; ?>
                  </tr>
                <?php $count++; endforeach; ?>
                
                <?php for ($i = 0; $i < 10 - $count; $i++): ?>
                  <tr style="height: 25px;">
                    <td colspan="<?php echo count($fields) ?>"/>
                  </tr>
                <?php endfor; ?>
                
                <tr style="height: 25px;" class="links">
                  <?php foreach ($fields as $field): ?>
                    <th nowrap align="<?php echo (isset($field[4])) ? $field[4] : 'left' ?>"><?php echo order_link($sf_params->get('order_by'), $field[1], $field[2], $sf_params->get('order'), $uri, $params, isset($field[5]) ? $field[5] : true)  ?></th>
                  <?php endforeach; ?>
                </tr>
              </table>
              <br/>
              <input type="hidden" id="<?php echo $uClass ?>_slug" name="<?php echo $uClass ?>_slug" />
              <input type="hidden" id="<?php echo $uClass ?>_nombre" name="<?php echo $uClass ?>_nombre" />
              <input type="hidden" id="<?php echo $uClass ?>_id" name="<?php echo $uClass ?>_id" />
              <input type="hidden" id="order_by" name="order_by" value="<?php echo $sf_params->get('order_by') ?>" />
              <input type="hidden" id="order" name="order" value="<?php echo $sf_params->get('order') ?>" />
              <input type="hidden" id="slug" name="slug" value="<?php echo $sf_params->get('slug') ?>" />
              
              <?php include_partial('Pager/pager_foot', array('pager'  => $pager, 'uri'    => $uri, 'params' => $params)) ?>
              
            </td>
          </tr>
        </table>
        
      <!-- </div> -->
    </td>
  </tr>
  
</table>